home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 13 / CU Amiga Magazine's Super CD-ROM 13 (1997)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1997-08].iso / CUCD / Graphics / Ghostscript / data / pdf_draw.ps < prev    next >
Text File  |  1997-04-12  |  8KB  |  315 lines

  1. %    Copyright (C) 1994, 1995 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % pdf_draw.ps
  16. % PDF drawing operations (graphics, text, and images).
  17.  
  18. % We don't handle the following PDF elements yet (identified by
  19. % page number in the reference manual):
  20. %    style strings (63-64), except in a few known fonts
  21. %    font descriptor resources (71-75), except for MissingWidth
  22. %    text clipping modes (104)
  23. %        What do these mean??
  24.  
  25. /.setlanguagelevel where { pop 2 .setlanguagelevel } if
  26. .currentglobal true .setglobal
  27. /pdfdict where { pop } { /pdfdict 100 dict def } ifelse
  28. GS_PDF_ProcSet begin
  29. pdfdict begin
  30.  
  31. % For simplicity, we use a single interpretation dictionary for all
  32. % PDF graphics operations, even though this is too liberal.
  33. /drawopdict 100 dict def
  34.  
  35. % ================================ Graphics ================================ %
  36.  
  37. % ---------------- Graphics state management ---------------- %
  38.  
  39. drawopdict begin
  40.             % Graphics state stack
  41.   /q { q } def
  42.   /Q { Q } def
  43.             % Graphics state setting
  44.   /cm { cm } def
  45.   /i { i } def
  46.   /J { J } def
  47.   /d { d } def
  48.   /j { j } def
  49.   /w { w } def
  50.   /M { M } def
  51. end
  52.  
  53. % ---------------- Color setting ---------------- %
  54.  
  55. /csgray            % <op> <csop> csgray -
  56.  { Page /Resources pget
  57.     { /ColorSpace knownoget
  58.        { /DefaultGray knownoget { 3 -1 roll exch 3 1 roll } if }
  59.       if
  60.     }
  61.    if pop cvx exec
  62.  } bdef
  63. /csrgb            % <op> <csop> csrgb -
  64.  { Page /Resources pget
  65.     { /ColorSpace knownoget
  66.        { /DefaultRGB knownoget { 3 -1 roll exch 3 1 roll } if }
  67.       if
  68.     }
  69.    if pop cvx exec
  70.  } bdef
  71. /cscmyk            % <op> <csop> cscmyk -
  72.  { pop cvx exec
  73.  } bdef
  74. /csresolve        % <csresource> csresolve <colorspace>
  75.  { Page /Resources pget not { 0 dict } if
  76.    /ColorSpace oget exch oget resolvecolorspace
  77.    dup type /nametype ne { dup length 1 eq { 0 get } if } if
  78.  } bdef
  79. /cset        % <c0> ... [- <sc1> - <sc3> <sc4>] <colorspace> cset -
  80.  { gsave setcolorspace mark currentcolor counttomark
  81.    grestore dup 2 add 1 roll cleartomark get exec
  82.  } bdef
  83.  
  84. %**************** sc and SC don't work, because the color space information
  85. %**************** isn't available at conversion time.
  86. drawopdict begin
  87.   /g { /g { cs sc1 } csgray } bdef
  88.   /rg { /rg { cs sc3 } csrgb } bdef
  89.   /k { /k { cs sc4 } cscmyk } bdef
  90.   /cs { csresolve cs } bdef
  91.   /sc { { null sc1 null sc3 sc4 } FillColorSpace cset } bdef
  92.   /G { /G { CS SC1 } csgray } bdef
  93.   /RG { /RG { CS SC3 } csrgb } bdef
  94.   /K { /K { CS SC4 } cscmyk } bdef
  95.   /CS { csresolve CS } bdef
  96.   /SC { { null SC1 null SC3 SC4 } StrokeColorSpace cset } bdef
  97. end
  98.  
  99. % ---------------- Paths ---------------- %
  100.  
  101. drawopdict begin
  102.             % Path construction
  103.   /m { m } def
  104.   /l { l } def
  105.   /c { c } def
  106.   /v { v } def
  107.   /y { y } def
  108.   /re { re } def
  109.   /h { h } def
  110.             % Path painting and clipping
  111.   /n { n } def
  112.   /S { S } def
  113.   /s { s } def
  114.   /f { f } def
  115.   /f* { f* } def
  116.   /B { B } def
  117.   /b { b } def
  118.   /B* { B* } def
  119.   /b* { b* } def
  120.   /W { W } def
  121.   /W* { W* } def
  122. end
  123.  
  124. % ---------------- XObjects ---------------- %
  125.  
  126. /xobjectprocs mark        % <dict> -proc- -
  127.   /Image { DoImage }
  128.   /Form { DoForm }
  129. .dicttomark readonly def
  130.  
  131. /ncompdict mark
  132.   /DeviceGray 1
  133.   /CalGray 1
  134.   /DeviceRGB 3
  135.   /CalRGB 3
  136.   /Lab 3
  137.   /DeviceCMYK 4
  138.   /CalCMYK 4
  139. .dicttomark readonly def
  140. /defaultdecodedict mark
  141.   /DeviceGray [0 1] readonly
  142.   /CalGray 1 index
  143.   /DeviceRGB [0 1 0 1 0 1] readonly
  144.   /CalRGB 1 index
  145.   /Lab
  146.    { 0 100 2 index 1 get /Range .knownget not { {-100 100 -100 100} } if
  147.      aload pop 6 array astore readonly
  148.    } bind
  149.   /DeviceCMYK [0 1 0 1 0 1 0 1] readonly
  150.   /CalCMYK 1 index
  151. .dicttomark readonly def
  152. /resolvecolorspace    % <cspace> resolvecolorspace <cspace>
  153.  { dup type /arraytype eq
  154.     { dup 0 get /Indexed eq
  155.        { dup 3 oget dup type /stringtype eq
  156.       { pop
  157.       }
  158.       {    % The color lookup table is a stream.
  159.         % Get its contents.
  160.         true resolvestream
  161.         1 index 2 get 1 add
  162.         ncompdict 3 index 1 get get mul
  163.         string readstring pop
  164.         1 index 3 3 -1 roll put
  165.       }
  166.      ifelse
  167.        }
  168.       if
  169.     }
  170.    if
  171.  } bdef
  172. /DoImage
  173.  { dup length dict
  174.    1 index /ColorSpace knownoget
  175.     { resolvecolorspace
  176.       dup type /arraytype eq { dup length 1 eq { 0 get } if } if
  177.       exch begin /ColorSpace exch def
  178.     }
  179.     { begin
  180.     }
  181.    ifelse
  182.    /ImageType 1 def
  183.         % Always define ImageMask appropriately.
  184.    dup /ImageMask knownoget dup { and } if
  185.      /ImageMask exch def
  186.    /Width 2 copy oget def
  187.    /Height 2 copy oget def
  188.    /BitsPerComponent 2 copy oget def
  189.    /Decode 2 copy knownoget not
  190.     {        % Decode is required for the PostScript image operators.
  191.       ImageMask
  192.        { [0 1]
  193.        }
  194.        { ColorSpace dup type /arraytype eq { 0 get } if dup /Indexed eq
  195.       { pop [ 0 1 BitsPerComponent bitshift 1 sub ] }
  196.       { defaultdecodedict exch get exec }
  197.      ifelse
  198.        }
  199.       ifelse
  200.     }
  201.    if def
  202.    /Interpolate 2 copy knownoget { def } { pop } ifelse
  203.    /ImageMatrix Width 0 0 Height neg 0 Height 6 array astore def
  204.         % Define DataSource as the width of the row buffer,
  205.         % which is what is needed if we're writing PostScript.
  206.    /DataSource 
  207.      Width BitsPerComponent mul
  208.      ImageMask not { Decode length 2 idiv mul } if
  209.      7 add 8 idiv
  210.    def
  211.         % Even though we're going to read data,
  212.         % pass false to resolvestream so that
  213.         % it doesn't try to use Length (which may not be present).
  214.    false resolvestream /Is_stream exch store
  215.    currentdict end ID
  216.  } bdef
  217. % Redefine Is, which constructs the data source for the image,
  218. % to retrieve the stream.  (pdf_2ps.ps redefines Is to copy the data too.)
  219. userdict /Is_stream null put
  220. /Is        % <imagedict> Is <imagedict> <datasource>
  221.  { Is_stream
  222.  } bdef
  223.  
  224. /DoForm
  225.  { dup [ /pop load 2 index
  226.     { false resolvestream pdfopdict .pdfrun }
  227.    aload pop ] cvx /PaintProc exch put
  228.    execform
  229.  } bdef
  230.  
  231. drawopdict begin
  232.   /Do
  233.     { PDFfile fileposition exch
  234.       Page /Resources pget not { 0 dict } if
  235.       /XObject oget exch oget
  236.       dup /Subtype get xobjectprocs exch get exec
  237.       PDFfile exch setfileposition
  238.     } bdef
  239. end
  240.  
  241. % ---------------- In-line images ---------------- %
  242.  
  243. % Undo the abbreviations in an in-line image dictionary.
  244. % Note that these can appear as keys, values, or members of array values.
  245. % /I is ambiguous; we check specially for it below.
  246. /unabbrevdict mark
  247.     % Top-level dictionary keys
  248.   /BPC /BitsPerComponent  /CS /ColorSpace  /D /Decode  /DP /DecodeParms
  249.   /F /Filter  /H /Height  /IM /ImageMask  /W /Width
  250.     % Values
  251.   /AHx /ASCIIHexDecode  /A85 /ASCII85Decode  /CC /CalCMYK
  252.   /CCF /CCITTFaxDecode  /CG /CalGray  /CR /CalRGB
  253.   /DCT /DCTDecode  /CMYK /DeviceCMYK  /G /DeviceGray  /RGB /DeviceRGB
  254.   /I /Indexed  /LZW /LZWDecode  /RL /RunLengthDecode
  255. .dicttomark readonly def
  256. /unabbrev        % <obj> unabbrev <obj'>
  257.  { dup type /nametype eq
  258.     { unabbrevdict 1 index .knownget { exch pop } if
  259.     }
  260.     { dup type /arraytype eq
  261.        { dup 0 1 2 index length 1 sub
  262.       { 2 copy get unabbrev put dup
  263.       }
  264.      for pop
  265.        }
  266.       if
  267.     }
  268.    ifelse
  269.  } bdef
  270.  
  271. drawopdict begin
  272.   /BI { mark } bdef
  273.   /ID
  274.     { counttomark
  275.        { counttomark 1 roll
  276.      dup /I eq { pop /Interpolate } { unabbrev } ifelse
  277.        }
  278.       repeat
  279.       /File PDFsource
  280.       .dicttomark DoImage
  281.       PDFsource token pop /EI ne { /ID cvx /syntaxerror signalerror } if
  282.     } bdef
  283. end
  284.  
  285. % ================================ Text ================================ %
  286.  
  287. drawopdict begin
  288.             % Text control
  289.   /BT { BT } def
  290.   /ET { ET } def
  291.   /Tc { Tc } def
  292.   /TL { TL } def
  293.   /Tr { Tr } def
  294.   /Ts { Ts } def
  295.   /Tw { Tw } def
  296.   /Tz { Tz } def
  297.             % Text positioning
  298.   /Td { Td } def
  299.   /TD { TD } def
  300.   /Tm { Tm } def
  301.   /T* { T* } def
  302.             % Text painting
  303.   /Tj { Tj } def
  304.   /' { ' } def
  305.   /" { " } def
  306.   /TJ { mark exch aload pop TJ } def
  307. end
  308.  
  309. end            % pdfdict
  310. end            % GS_PDF_ProcSet
  311. .setglobal
  312.